home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / F9V6A0 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  8.0 KB  |  281 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.accessibility.Accessible;
  4. import com.sun.java.accessibility.AccessibleContext;
  5. import com.sun.java.accessibility.AccessibleState;
  6. import com.sun.java.swing.event.ChangeListener;
  7. import com.sun.java.swing.event.EventListenerList;
  8. import com.sun.java.swing.plaf.ScrollBarUI;
  9. import java.awt.Adjustable;
  10. import java.awt.Component;
  11. import java.awt.Container;
  12. import java.awt.Dimension;
  13. import java.awt.event.AdjustmentEvent;
  14. import java.awt.event.AdjustmentListener;
  15.  
  16. public class JScrollBar extends JComponent implements Adjustable, Accessible {
  17.    private ChangeListener fwdAdjustmentEvents;
  18.    protected BoundedRangeModel model;
  19.    protected int orientation;
  20.    protected int unitIncrement;
  21.    protected int blockIncrement;
  22.    static Class class$java$awt$event$AdjustmentListener;
  23.  
  24.    public JScrollBar() {
  25.       this(1);
  26.    }
  27.  
  28.    public JScrollBar(int orientation) {
  29.       this(orientation, 0, 10, 0, 100);
  30.    }
  31.  
  32.    public JScrollBar(int orientation, int value, int extent, int min, int max) {
  33.       this.fwdAdjustmentEvents = new ModelListener(this);
  34.       this.checkOrientation(orientation);
  35.       this.unitIncrement = 1;
  36.       this.blockIncrement = extent == 0 ? 1 : extent;
  37.       this.orientation = orientation;
  38.       this.model = new DefaultBoundedRangeModel(value, extent, min, max);
  39.       this.model.addChangeListener(this.fwdAdjustmentEvents);
  40.       this.updateUI();
  41.    }
  42.  
  43.    public void addAdjustmentListener(AdjustmentListener l) {
  44.       EventListenerList var10000 = super.listenerList;
  45.       Class var10001 = class$java$awt$event$AdjustmentListener;
  46.       if (var10001 == null) {
  47.          try {
  48.             var10001 = Class.forName("java.awt.event.AdjustmentListener");
  49.          } catch (ClassNotFoundException var2) {
  50.             throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  51.          }
  52.  
  53.          class$java$awt$event$AdjustmentListener = var10001;
  54.       }
  55.  
  56.       var10000.add(var10001, l);
  57.    }
  58.  
  59.    private void checkOrientation(int orientation) {
  60.       switch (orientation) {
  61.          case 0:
  62.          case 1:
  63.             return;
  64.          default:
  65.             throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL");
  66.       }
  67.    }
  68.  
  69.    protected void fireAdjustmentValueChanged(int id, int type, int value) {
  70.       Object[] listeners = super.listenerList.getListenerList();
  71.       AdjustmentEvent e = null;
  72.  
  73.       for(int i = listeners.length - 2; i >= 0; i -= 2) {
  74.          Object var10000 = listeners[i];
  75.          Class var10001 = class$java$awt$event$AdjustmentListener;
  76.          if (var10001 == null) {
  77.             try {
  78.                var10001 = Class.forName("java.awt.event.AdjustmentListener");
  79.             } catch (ClassNotFoundException var7) {
  80.                throw new NoClassDefFoundError(((Throwable)var7).getMessage());
  81.             }
  82.  
  83.             class$java$awt$event$AdjustmentListener = var10001;
  84.          }
  85.  
  86.          if (var10000 == var10001) {
  87.             if (e == null) {
  88.                e = new AdjustmentEvent(this, id, type, value);
  89.             }
  90.  
  91.             ((AdjustmentListener)listeners[i + 1]).adjustmentValueChanged(e);
  92.          }
  93.       }
  94.  
  95.    }
  96.  
  97.    public AccessibleContext getAccessibleContext() {
  98.       if (super.accessibleContext == null) {
  99.          super.accessibleContext = new AccessibleJScrollBar(this);
  100.       }
  101.  
  102.       return super.accessibleContext;
  103.    }
  104.  
  105.    public int getBlockIncrement() {
  106.       return this.blockIncrement;
  107.    }
  108.  
  109.    public int getBlockIncrement(int direction) {
  110.       return this.blockIncrement;
  111.    }
  112.  
  113.    public int getMaximum() {
  114.       return this.getModel().getMaximum();
  115.    }
  116.  
  117.    public Dimension getMaximumSize() {
  118.       Dimension pref = ((JComponent)this).getPreferredSize();
  119.       return this.getOrientation() == 1 ? new Dimension(pref.width, 32767) : new Dimension(32767, pref.height);
  120.    }
  121.  
  122.    public int getMinimum() {
  123.       return this.getModel().getMinimum();
  124.    }
  125.  
  126.    public Dimension getMinimumSize() {
  127.       Dimension pref = ((JComponent)this).getPreferredSize();
  128.       return this.orientation == 1 ? new Dimension(pref.width, 5) : new Dimension(5, pref.height);
  129.    }
  130.  
  131.    public BoundedRangeModel getModel() {
  132.       return this.model;
  133.    }
  134.  
  135.    public int getOrientation() {
  136.       return this.orientation;
  137.    }
  138.  
  139.    public ScrollBarUI getUI() {
  140.       return (ScrollBarUI)super.ui;
  141.    }
  142.  
  143.    public String getUIClassID() {
  144.       return "ScrollBarUI";
  145.    }
  146.  
  147.    public int getUnitIncrement() {
  148.       return this.unitIncrement;
  149.    }
  150.  
  151.    public int getUnitIncrement(int direction) {
  152.       return this.unitIncrement;
  153.    }
  154.  
  155.    public int getValue() {
  156.       return this.getModel().getValue();
  157.    }
  158.  
  159.    public boolean getValueIsAdjusting() {
  160.       return this.getModel().getValueIsAdjusting();
  161.    }
  162.  
  163.    public int getVisibleAmount() {
  164.       return this.getModel().getExtent();
  165.    }
  166.  
  167.    public void removeAdjustmentListener(AdjustmentListener l) {
  168.       EventListenerList var10000 = super.listenerList;
  169.       Class var10001 = class$java$awt$event$AdjustmentListener;
  170.       if (var10001 == null) {
  171.          try {
  172.             var10001 = Class.forName("java.awt.event.AdjustmentListener");
  173.          } catch (ClassNotFoundException var2) {
  174.             throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  175.          }
  176.  
  177.          class$java$awt$event$AdjustmentListener = var10001;
  178.       }
  179.  
  180.       var10000.remove(var10001, l);
  181.    }
  182.  
  183.    public void setBlockIncrement(int blockIncrement) {
  184.       int oldValue = this.blockIncrement;
  185.       this.blockIncrement = blockIncrement;
  186.       ((JComponent)this).firePropertyChange("blockIncrement", oldValue, blockIncrement);
  187.    }
  188.  
  189.    public void setEnabled(boolean x) {
  190.       super.setEnabled(x);
  191.       Component[] children = ((Container)this).getComponents();
  192.  
  193.       for(int i = 0; i < children.length; ++i) {
  194.          children[i].setEnabled(x);
  195.       }
  196.  
  197.    }
  198.  
  199.    public void setMaximum(int maximum) {
  200.       this.getModel().setMaximum(maximum);
  201.    }
  202.  
  203.    public void setMinimum(int minimum) {
  204.       this.getModel().setMinimum(minimum);
  205.    }
  206.  
  207.    public void setModel(BoundedRangeModel newModel) {
  208.       Integer oldValue = null;
  209.       BoundedRangeModel oldModel = this.model;
  210.       if (this.model != null) {
  211.          this.model.removeChangeListener(this.fwdAdjustmentEvents);
  212.          oldValue = new Integer(this.model.getValue());
  213.       }
  214.  
  215.       this.model = newModel;
  216.       if (this.model != null) {
  217.          this.model.addChangeListener(this.fwdAdjustmentEvents);
  218.       }
  219.  
  220.       ((JComponent)this).firePropertyChange("model", oldModel, this.model);
  221.       if (super.accessibleContext != null) {
  222.          super.accessibleContext.firePropertyChange("AccessibleValue", oldValue, new Integer(this.model.getValue()));
  223.       }
  224.  
  225.    }
  226.  
  227.    public void setOrientation(int orientation) {
  228.       this.checkOrientation(orientation);
  229.       this.orientation = orientation;
  230.       ((JComponent)this).firePropertyChange("orientation", orientation, orientation);
  231.       if (orientation != orientation && super.accessibleContext != null) {
  232.          super.accessibleContext.firePropertyChange("AccessibleState", orientation == 1 ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL, orientation == 1 ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL);
  233.       }
  234.  
  235.    }
  236.  
  237.    public void setUnitIncrement(int unitIncrement) {
  238.       int oldValue = this.unitIncrement;
  239.       this.unitIncrement = unitIncrement;
  240.       ((JComponent)this).firePropertyChange("unitIncrement", oldValue, unitIncrement);
  241.    }
  242.  
  243.    public void setValue(int value) {
  244.       BoundedRangeModel m = this.getModel();
  245.       int oldValue = m.getValue();
  246.       m.setValue(value);
  247.       if (super.accessibleContext != null) {
  248.          super.accessibleContext.firePropertyChange("AccessibleValue", new Integer(oldValue), new Integer(m.getValue()));
  249.       }
  250.  
  251.    }
  252.  
  253.    public void setValueIsAdjusting(boolean b) {
  254.       BoundedRangeModel m = this.getModel();
  255.       boolean oldValue = m.getValueIsAdjusting();
  256.       m.setValueIsAdjusting(b);
  257.       if (oldValue != b && super.accessibleContext != null) {
  258.          super.accessibleContext.firePropertyChange("AccessibleState", oldValue ? AccessibleState.BUSY : null, b ? AccessibleState.BUSY : null);
  259.       }
  260.  
  261.    }
  262.  
  263.    public void setValues(int newValue, int newExtent, int newMin, int newMax) {
  264.       BoundedRangeModel m = this.getModel();
  265.       int oldValue = m.getValue();
  266.       m.setRangeProperties(newValue, newExtent, newMin, newMax, m.getValueIsAdjusting());
  267.       if (super.accessibleContext != null) {
  268.          super.accessibleContext.firePropertyChange("AccessibleValue", new Integer(oldValue), new Integer(m.getValue()));
  269.       }
  270.  
  271.    }
  272.  
  273.    public void setVisibleAmount(int extent) {
  274.       this.getModel().setExtent(extent);
  275.    }
  276.  
  277.    public void updateUI() {
  278.       ((JComponent)this).setUI((ScrollBarUI)UIManager.getUI(this));
  279.    }
  280. }
  281.